from sqlalchemy import create_engine
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from apscheduler.schedulers.asyncio import AsyncIOScheduler

from app.db.DBConfig import get_mysql_url

# --- 引擎创建 ---
# 为 APScheduler 创建一个独立的同步引擎
async_db_url = get_mysql_url()
sync_db_url = async_db_url.replace("+aiomysql", "+pymysql")
sync_engine = create_engine(sync_db_url)

# --- 调度器配置 ---
jobstores = {
    'default': SQLAlchemyJobStore(engine=sync_engine)
}

# --- 实例化并导出 scheduler ---
scheduler = AsyncIOScheduler(jobstores=jobstores)